package com.wntms.wgj.dao;

import com.wntms.wgj.pojo.CollectionSettle;
import com.wntms.wgj.pojo.CustomerInformations;
import com.wntms.wgj.pojo.CustomerIns;
import com.wntms.wgj.pojo.FreightContracts;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CollectionSettleDao {
    /**
     * 查询代收货款表所有数据
     * @return
     */
    @Select("select * from collection_settle")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "fid",column = "fid"),
            @Result(property = "ciid",column = "ciid"),
            @Result(property = "cid",column = "cid"),
            @Result(property = "receivables",column = "receivables"),
            @Result(property = "afterReceivables",column = "after_receivables"),
            @Result(property = "commission",column = "commission"),
            @Result(property = "commissionRate",column = "commission_rate"),
            @Result(property = "businessType",column = "business_type"),
            @Result(property = "isPayment",column = "ispayment"),
            @Result(property = "commissionReceive",column = "commission_receive"),
            @Result(property = "commissionReceivables",column = "commission_receivables"),
            @Result(property = "freightContracts",column = "fid",javaType = FreightContracts.class,
                    one = @One(select = "com.wntms.wgj.dao.FreightContractDaos.findById")),
            @Result(property = "customerIns",column = "ciid",javaType = CustomerIns.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInDaos.findById")),
            @Result(property = "customerInformations",column = "cid",javaType = CustomerInformations.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInformationDaos.findById"))
    })
    public List<CollectionSettle> findAll();

    /**
     * 代收结算
     * @param collectionSettle
     * @return
     */
    @Update("update collection_settle set ispayment = #{isPayment},commission_receive = #{commissionReceive},commission_receivables = #{commissionReceivables} where id = #{id}")
    public int updateSettle(CollectionSettle collectionSettle);

    /**
     * 删除代收结算记录
     * @param id
     * @return
     */
    @Delete("delete from collection_settle where id = #{id}")
    public int deleteSettle(Integer id);

    /**
     * 变更货款，返款类型
     * @param collectionSettle
     * @return
     */
    @Update("update collection_settle set after_receivables = #{afterReceivables},business_type = #{businessType} where id = #{id}")
    public int updateBusiness(CollectionSettle collectionSettle);

    /**
     * 根据fid查询代收结算单条记录
     * @param fid
     * @return
     */
    @Select("select * from collection_settle where fid = #{fid}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "fid",column = "fid"),
            @Result(property = "ciid",column = "ciid"),
            @Result(property = "cid",column = "cid"),
            @Result(property = "receivables",column = "receivables"),
            @Result(property = "afterReceivables",column = "after_receivables"),
            @Result(property = "commission",column = "commission"),
            @Result(property = "commissionRate",column = "commission_rate"),
            @Result(property = "businessType",column = "business_type"),
            @Result(property = "isPayment",column = "ispayment"),
            @Result(property = "commissionReceive",column = "commission_receive"),
            @Result(property = "commissionReceivables",column = "commission_receivables"),
            @Result(property = "freightContracts",column = "fid",javaType = FreightContracts.class,
                    one = @One(select = "com.wntms.wgj.dao.FreightContractDaos.findById")),
            @Result(property = "customerIns",column = "ciid",javaType = CustomerIns.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInDaos.findById")),
            @Result(property = "customerInformations",column = "cid",javaType = CustomerInformations.class,
                    one = @One(select = "com.wntms.wgj.dao.CustomerInformationDaos.findById"))
    })
    public CollectionSettle findByFid(String fid);
}
